<?php
/** 
 * 相册模型类
 * 
 * @author      sinalma  <sinalma@foxmail.com>
 * @version     1.0 版本号
 */
namespace app\admin\model;

use think\Db;
use think\Model;
use think\Pageintor;

/** 
 * Class Album
 * 模型类 
 *
 * @package app\index\controller
 * @author      sinalma  <sinalma@foxmail.com>
 * @version     1.0 版本号
 */ 
class Album extends Model
{
    protected $table = 'sinblog_album';


    /**  
     * 获取相册模块数据(页)
     * not use
     * 
     * @access public 
     * @param mixed $limit 限制字符串
     * @param mixed $pageNum 每页条数
     * @return array (fields,photos)
     */ 
    public function getPhotos($limit,$pageNum){
        // 获取所有字段
        $fields = $this->getFields();
        // 获取当前页照片数据
        $photos = $this->query("SELECT * from '{$this->table}' order by pic_id desc '{$limit}'");
        $data = array();
        $data['fields'] = $fields;
        $data['photos'] = $photos;
        return $data;
    }


    /**  
     * 获取所有照片信息
     * TODO 暂未实现（审核）
     * 
     * @access public 
     * @return array 
     */ 
    public function getablumlist(){
        $list = Db::name('messages')->where(1)->paginate(10);  

    }


    /**  
     * 获取相册模块数据(页)
     * 已废弃
     * not use
     * 
     * @access public 
     * @param mixed $picN 图片名
     * @param mixed $link 原图链接
     * @param mixed $smallSuffix 缩略图后缀
     * @param mixed $picType 图片类型(后缀)
     * @param mixed $date 如果不传,默认为当前时间 
     * @return array 数组
     */	
	public function insertPic($name,$link,$suffix,$note,$addr,$device,$type,$time){
		$samll_link = $link ."?". $suffix;
        $sql = "INSERT into sinblog_album(name,link,small_link,note,type,time,device,address) values('{$name}','{$link}','{$samll_link}','{$note}','{$type}','{$time}','{$device}','{$addr}')";
        $res = $this->execute($sql);
        return $res;
	}

     /**  
     * 获取相册所有字段，开发中浏览使用
     * not use
     * 
     * @access private
     */
    private function getFields(){

        $fields = array();
        $fieldStr = '';
        $res = $db->query("desc sinblog_album;");
        for($i=0;$i<count($res);++$i){
             $fields[] = $res[$i]['Field'];
             $fieldStr .= $res[$i]['Field'];
             $fieldStr .= ',';
        }
        return $fields;
    }

    /**  
     * 获取总文章数 
     * not use
     * 
     * @access public 
     * @return int 
     */  
    public function getCount(){
      $data = $this->query("SELECT count(*) as count from typecho_album");
            return $data[0]["count"];
    }    
}